import { FirstLetter, GroupTemplateItem } from './template.d';

class GroupTemplate {
  groupTemplate: GroupTemplateItem[] = [];

  addItem(firstLetterObj: FirstLetter) {
    const foundIndex = this.groupTemplate.findIndex((groupTemplateItem) => (
      groupTemplateItem.label === firstLetterObj.firstLetter
    ));

    if (foundIndex === -1) {
      this.groupTemplate.push({
        label: firstLetterObj.firstLetter,
        templateOption: [{
          uuid: firstLetterObj.uuid,
          title: firstLetterObj.title
        }]
      });
    }

    if (foundIndex !== -1) {
      this.groupTemplate[foundIndex].templateOption.push({
        uuid: firstLetterObj.uuid,
        title: firstLetterObj.title
      });
    }
  }
}

export default GroupTemplate;
